﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Hermes.Web.OrderLines
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int ID=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(ID);
				}
			}
		}
			
	private void ShowInfo(int ID)
	{
		Hermes.BLL.OrderLines bll=new Hermes.BLL.OrderLines();
		Hermes.Model.OrderLines model=bll.GetModel(ID);
		this.lblID.Text=model.ID.ToString();
		this.txtOrderID.Text=model.OrderID.ToString();
		this.txtOrderNUmber.Text=model.OrderNUmber;
		this.txtSKU.Text=model.SKU;
		this.txtEBaySKU.Text=model.EBaySKU;
		this.txtQTY.Text=model.QTY.ToString();
		this.txtPrice.Text=model.Price.ToString();
		this.txtLastUpdate.Text=model.LastUpdate.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtOrderID.Text))
			{
				strErr+="OrderID格式错误！\\n";	
			}
			if(this.txtOrderNUmber.Text.Trim().Length==0)
			{
				strErr+="OrderNUmber不能为空！\\n";	
			}
			if(this.txtSKU.Text.Trim().Length==0)
			{
				strErr+="SKU不能为空！\\n";	
			}
			if(this.txtEBaySKU.Text.Trim().Length==0)
			{
				strErr+="EBaySKU不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtQTY.Text))
			{
				strErr+="QTY格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtPrice.Text))
			{
				strErr+="Price格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtLastUpdate.Text))
			{
				strErr+="LastUpdate格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int ID=int.Parse(this.lblID.Text);
			int OrderID=int.Parse(this.txtOrderID.Text);
			string OrderNUmber=this.txtOrderNUmber.Text;
			string SKU=this.txtSKU.Text;
			string EBaySKU=this.txtEBaySKU.Text;
			int QTY=int.Parse(this.txtQTY.Text);
			decimal Price=decimal.Parse(this.txtPrice.Text);
			DateTime LastUpdate=DateTime.Parse(this.txtLastUpdate.Text);


			Hermes.Model.OrderLines model=new Hermes.Model.OrderLines();
			model.ID=ID;
			model.OrderID=OrderID;
			model.OrderNUmber=OrderNUmber;
			model.SKU=SKU;
			model.EBaySKU=EBaySKU;
			model.QTY=QTY;
			model.Price=Price;
			model.LastUpdate=LastUpdate;

			Hermes.BLL.OrderLines bll=new Hermes.BLL.OrderLines();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
